/*
CpGears v1.0

Copyright (c) 2010 Yves Riel http://www.flash-factor.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cpgears {
	import flash.utils.Dictionary;
	import cpgears.helpers.StringUtil;
	
	/**
	 * Enumeration class containing the Captivate widget modes.
	 * 
	 * @author Whyves
	 */
	public class WidgetMode {
		
		// TRICKY: The static dictionairy must be the first one declared.
		private static var mEnumeration:Dictionary = new Dictionary();
		
		/**
		 * @private
		 */
		public static const INITIALIZING:WidgetMode = new WidgetMode("Initializing");
		
		/**
		 *  In the Edit mode, the widget displays it self to be configured in the property editor.
		 */
		public static const EDIT:WidgetMode = new WidgetMode("Edit");
		
		/**
		 * In the Preview mode, the widget displays itself as it usually looks like.
		 */
		public static const PREVIEW:WidgetMode = new WidgetMode("Preview");
		
		/**
		 * In the Runtime mode, the widget displays itself and responds to the user interactions.
		 */
		public static const RUNTIME:WidgetMode = new WidgetMode("RunTime");
		
		/**
		 * In the Stage mode, the widget displays itself on the Captivate stage according to how the user configured it.
		 */
		public static const STAGE:WidgetMode = new WidgetMode("Stage");
		
		private var mName:String = null;
		
		/**
		 * Creates a mode.
		 * 
		 * @param	name The mode internal name.
		 */
		public function WidgetMode(name:String) {
			if (StringUtil.isNullOrEmpty(name)) throw new ArgumentError("'str' parameter cannot be null or empty.");
			mName = name;
			mEnumeration[name] = this;
		}
		
		/**
		 * Returns the mode matching the internal name.
		 * 
		 * @param	modeName The internal name of the mode.
		 * @return The mode matching the internal name.
		 */
		public static function getModeFromName(modeName:String):WidgetMode {
			return (mEnumeration.hasOwnProperty(modeName)) ? mEnumeration[modeName] : null;
		}
		
		/**
		 * Returns the mode's internal name
		 */
		public function get value():String {
			return mName;
		}
	}
}